結束 HTML, Typescript 範例測試,講師也分享幾個快速寫單元測試的方法,還有他習慣的開發方式,筆者覺得真的蠻方便的,我們一起來看看
line 2
// ******************* 在 describe 前面加 f *******************
fdescribe('Testing Functions Are Called xxxx測試大綱', () => {
let component: XXXComponent;
let componentFixture: ComponentFixture<XXXComponent>;
});
如附圖,只會跑 9 個測試案例
只想測試「某個案例」,在 it 前面加 f
describe('Testing Functions Are Called xxxx測試大綱', () => {
let component: XXXComponent;
let componentFixture: ComponentFixture<XXXComponent>;
beforeEach(waitForAsync(() => {
configureTestingModule({
declarations: [
XXXComponent,
]
}).compileComponents();
}));
beforeEach(() => {
componentFixture = TestBed.createComponent(XXXComponent);
component = componentFixture.componentInstance;
componentFixture.detectChanges();
});
// ******************* 在 it 前面加 f *******************
fit('這裡應該要....', () => {
//Assign
//Act
//Assert
expect(component).toBeTruthy();
});
});
line 2
// ******************* 在 describe 前面加 x *******************
xdescribe('Testing Functions Are Called xxxx測試大綱', () => {
let component: XXXComponent;
let componentFixture: ComponentFixture<XXXComponent>;
});
全部測試案例共 110 個,disable line 6
xdescribe,只會跑101個
只想測試「某個案例」,在 it 前面加 x
describe('Testing Functions Are Called xxxx測試大綱', () => {
let component: XXXComponent;
let componentFixture: ComponentFixture<XXXComponent>;
beforeEach(waitForAsync(() => {
configureTestingModule({
declarations: [
XXXComponent,
]
}).compileComponents();
}));
beforeEach(() => {
componentFixture = TestBed.createComponent(XXXComponent);
component = componentFixture.componentInstance;
componentFixture.detectChanges();
});
// ******************* 在 it 前面加 x *******************
xit('這裡應該要....', () => {
//Assign
//Act
//Assert
expect(component).toBeTruthy();
});
});
line 6
xit,只會跑109個